feat(cli): add async server wait workflow - #410
Conversation
📝 WalkthroughWalkthroughThis change adds load-aware inspect status contracts, a new ChangesAsync loading workflow
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant CLI as wait CLI
participant Surface as Reusable client surface
participant Inspect as /api/v1/inspect
participant Runtime as Loading tracker
CLI->>Surface: start authenticated wait workflow
Surface->>Inspect: poll tracked server status
Inspect->>Runtime: read loading state
Runtime-->>Inspect: return status and availability
Inspect-->>CLI: return connected, terminal, or timeout result
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (2)
docs/zh/commands/inspect.md (1)
21-21: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winBring the edited public command pages into the documentation contract.
docs/zh/commands/inspect.md#L21-L21: Add frontmatter and replace./wait.mdwith the absolute/zh/commands/waitlink.docs/zh/commands/run.md#L23-L23: Add required frontmatter.As per coding guidelines, “Include frontmatter for all public documentation pages” and “Use absolute internal links in documentation.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@docs/zh/commands/inspect.md` at line 21, Update docs/zh/commands/inspect.md at lines 21-21 by adding the required frontmatter and replacing the relative ./wait.md link with the absolute /zh/commands/wait link. Update docs/zh/commands/run.md at lines 23-23 by adding the required frontmatter, following the existing public documentation page conventions.Source: Coding guidelines
src/commands/shared/clientSurfaceAttachment.test.ts (1)
194-215: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse the shared mock factories for the new test fixtures.
src/commands/shared/clientSurfaceAttachment.test.ts#L194-L215: Create the cached-session fixture throughtest/unit-utils/MockFactories.ts, extending it if needed.src/commands/wait/wait.test.ts#L7-L39: Create the attachment context and inspect-response fixture data through the shared factories.As per coding guidelines, “Use
test/unit-utils/MockFactories.tsfor consistent mock data and mock factories.”🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/commands/shared/clientSurfaceAttachment.test.ts` around lines 194 - 215, Use the shared mock factories from test/unit-utils/MockFactories.ts for both affected test fixtures: in src/commands/shared/clientSurfaceAttachment.test.ts lines 194-215, create the cached-session data through the appropriate factory and extend it with required fields; in src/commands/wait/wait.test.ts lines 7-39, create the attachment context and inspect-response data through the shared factories. Preserve each test’s existing behavior and assertions.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/en/commands/index.md`:
- Line 82: Update docs/en/commands/index.md lines 82-82 to describe wait as
waiting for configured static servers to become connected and available. Update
docs/en/commands/inspect.md lines 36-36 to state that scripts wait for servers
to be connected and available, and replace the relative ./wait.md link with the
absolute internal /commands/wait link.
In `@docs/en/guide/advanced/fast-startup.md`:
- Line 65: Update the readiness descriptions for the connected state in
docs/en/guide/advanced/fast-startup.md lines 65-65 and
docs/zh/guide/advanced/fast-startup.md lines 65-65 to clarify that tool
invocation requires both connected and available, not connected alone; preserve
the respective English and Chinese wording.
In `@src/commands/run/run.ts`:
- Around line 256-334: Update the status dispatch around the existing
connected-and-available check to explicitly handle server.status === 'connected'
with server.available === false. Route this transitional state through
statusErrorResponse using server_loading semantics, with guidance to wait for
the server to become available rather than suggesting a restart; leave the
existing pending/loading, OAuth, and generic unavailable branches unchanged.
In `@src/commands/wait/wait.ts`:
- Around line 69-70: Update the status handling around the wait command’s
attachment check to handle auth_required separately, preserving its original
error code and the context-aware recovery guidance from
formatClientSurfaceAuthRequiredMessage. Only non-authentication failures should
continue throwing server_status_unavailable with 1mcp inspect.
- Around line 47-55: Update waitCommand to validate and normalize the complete
WaitCommandOptions object with the project’s Zod schema before reading timeout
or starting attachment/polling. Include timeout, filter/tag, and format fields
in the boundary validation, then use the parsed options for subsequent logic
while preserving the existing positive-timeout requirement and WaitCommandError
behavior.
In `@src/transport/http/routes/inspectRoutes.ts`:
- Around line 435-454: Apply the same target authorization or scope gate used
for tool targets before the static-server early return in the inspect route.
Ensure out-of-scope static servers return 404 before exposing status,
authorizationUrl, or error metadata, while preserving the existing payload for
authorized static servers.
---
Nitpick comments:
In `@docs/zh/commands/inspect.md`:
- Line 21: Update docs/zh/commands/inspect.md at lines 21-21 by adding the
required frontmatter and replacing the relative ./wait.md link with the absolute
/zh/commands/wait link. Update docs/zh/commands/run.md at lines 23-23 by adding
the required frontmatter, following the existing public documentation page
conventions.
In `@src/commands/shared/clientSurfaceAttachment.test.ts`:
- Around line 194-215: Use the shared mock factories from
test/unit-utils/MockFactories.ts for both affected test fixtures: in
src/commands/shared/clientSurfaceAttachment.test.ts lines 194-215, create the
cached-session data through the appropriate factory and extend it with required
fields; in src/commands/wait/wait.test.ts lines 7-39, create the attachment
context and inspect-response data through the shared factories. Preserve each
test’s existing behavior and assertions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7566ba78-fdb3-4ec3-982b-cbde8db4b728
📒 Files selected for processing (36)
README.mddocs/.vitepress/config/en.tsdocs/.vitepress/config/zh.tsdocs/en/commands/index.mddocs/en/commands/inspect.mddocs/en/commands/run.mddocs/en/commands/wait.mddocs/en/guide/advanced/fast-startup.mddocs/zh/commands/index.mddocs/zh/commands/inspect.mddocs/zh/commands/run.mddocs/zh/commands/wait.mddocs/zh/guide/advanced/fast-startup.mdsrc/commands/inspect/inspect.tssrc/commands/inspect/inspectUtils.tssrc/commands/instructions/instructionsUtils.tssrc/commands/run/run.rest-errors.test.tssrc/commands/run/run.rest-fallback.test.tssrc/commands/run/run.rest-primary.test.tssrc/commands/run/run.tssrc/commands/shared/apiClient.tssrc/commands/shared/clientSurfaceAttachment.test.tssrc/commands/shared/clientSurfaceAttachment.tssrc/commands/shared/commandRunner.test.tssrc/commands/shared/commandRunner.tssrc/commands/shared/filterSelectionQuery.tssrc/commands/shared/inspectApiSchemas.tssrc/commands/wait/index.tssrc/commands/wait/wait.test.tssrc/commands/wait/wait.tssrc/index.tssrc/transport/http/routes/apiRoutes.test.tssrc/transport/http/routes/inspectHelpers.test.tssrc/transport/http/routes/inspectHelpers.tssrc/transport/http/routes/inspectRoutes.tssrc/types/serverStatus.ts
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
docs/zh/guide/advanced/fast-startup.md (1)
59-71: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick winRemove the misleading
loadingsection timeout reference.The deprecation row says
asyncLoading.timeoutis a no-op, but the next “Configuration” sentence re‑introduces a non-existent JSONloadingtimeout path. Keep the section focused onasyncLoading.batchDelay/--async-batch-delay, and remove or rewrite the timeout example so users do not configure a timeout that has no effect.Do the same change in the parallel English page.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@docs/zh/guide/advanced/fast-startup.md` around lines 59 - 71, Update the “配置” guidance in the Chinese fast-startup documentation and its parallel English page to remove the misleading JSON loading timeout reference. Keep the section focused on the supported async loading settings, especially asyncLoading.batchDelay and --async-batch-delay, and do not suggest configuring the deprecated no-op asyncLoading.timeout.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/zh/guide/advanced/fast-startup.md`:
- Line 73: Update the internal configuration link in the Chinese fast-startup
guide to use the `/zh/` locale prefix, while preserving the existing
configuration section anchor and link text.
---
Outside diff comments:
In `@docs/zh/guide/advanced/fast-startup.md`:
- Around line 59-71: Update the “配置” guidance in the Chinese fast-startup
documentation and its parallel English page to remove the misleading JSON
loading timeout reference. Keep the section focused on the supported async
loading settings, especially asyncLoading.batchDelay and --async-batch-delay,
and do not suggest configuring the deprecated no-op asyncLoading.timeout.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ea97f59e-2bb9-40eb-b1d8-74ab455eb1b1
📒 Files selected for processing (20)
docs/en/commands/index.mddocs/en/commands/inspect.mddocs/en/commands/wait.mddocs/en/guide/advanced/fast-startup.mddocs/zh/commands/index.mddocs/zh/commands/inspect.mddocs/zh/commands/run.mddocs/zh/commands/wait.mddocs/zh/guide/advanced/fast-startup.mdsrc/commands/run/run.rest-primary.test.tssrc/commands/run/run.tssrc/commands/shared/clientSurfaceAttachment.test.tssrc/commands/shared/clientSurfaceAttachment.tssrc/commands/wait/index.tssrc/commands/wait/wait.test.tssrc/commands/wait/wait.tssrc/transport/http/routes/apiRoutes.test.tssrc/transport/http/routes/inspectRoutes.tstest/e2e/commands/inspect.test.tstest/unit-utils/MockFactories.ts
🚧 Files skipped from review as they are similar to previous changes (13)
- docs/en/commands/index.md
- docs/zh/commands/index.md
- src/commands/shared/clientSurfaceAttachment.test.ts
- src/commands/wait/index.ts
- docs/zh/commands/inspect.md
- docs/zh/commands/run.md
- docs/zh/commands/wait.md
- src/commands/run/run.rest-primary.test.ts
- docs/en/commands/wait.md
- docs/en/commands/inspect.md
- docs/en/guide/advanced/fast-startup.md
- src/commands/run/run.ts
- src/transport/http/routes/inspectRoutes.ts
| @@ -165,140 +72,38 @@ npx -y @1mcp/agent --config mcp.json --enable-async-loading \ | |||
|
|
|||
| 有关选项的完整列表,请参阅 **[配置深入探讨](/guide/essentials/configuration#loading-section-async-loading)**。 | |||
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Use the Chinese locale prefix in this internal link.
This page is under docs/zh/, but the link targets the English route.
Proposed fix
-[配置深入探讨](/guide/essentials/configuration#loading-section-async-loading)
+[配置深入探讨](/zh/guide/essentials/configuration#loading-section-async-loading)As per coding guidelines, Chinese content is served from /zh/ paths, with locale navigation configured in .vitepress/config/en.ts and .vitepress/config/zh.ts.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| 有关选项的完整列表,请参阅 **[配置深入探讨](/guide/essentials/configuration#loading-section-async-loading)**。 | |
| 有关选项的完整列表,请参阅 **[配置深入探讨](/zh/guide/essentials/configuration#loading-section-async-loading)**。 |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@docs/zh/guide/advanced/fast-startup.md` at line 73, Update the internal
configuration link in the Chinese fast-startup guide to use the `/zh/` locale
prefix, while preserving the existing configuration section anchor and link
text.
Source: Coding guidelines
Summary
1mcp wait [server]and status-awarerunbehavior that never falls through to an unsafe early MCP sessionValidation
pnpm lintpnpm typecheckpnpm buildpnpm docs:buildpnpm test:unit(298 files, 4,333 tests)Existing Vitest mock-hoisting, VitePress highlighting/chunk-size, and Node deprecation warnings remain unchanged.
Closes #395
Closes #405
Summary by CodeRabbit
New Features
waitCLI command to monitor configured static servers until they are connected and available.runandinspectworkflows with clearer server readiness and recovery guidance.Documentation
wait.